# @before-stub-for-debug-begin
from python3problem69 import *
from typing import *
# @before-stub-for-debug-end


#
# @lc app=leetcode.cn id=69 lang=python3
#
# [69] x 的平方根 
#

# @lc code=start
class Solution:
    def mySqrt(self, x: int) -> int:
        left = 0
        right = x
        ans = 0
        while left <= right:
            mid = left + (right - left) // 2
            if self.check(x, mid):
                ans = mid
                left = mid + 1
            else:
                right = mid - 1
        return ans
    
    def check(self, x: int, mid: int) -> bool:
        if mid ** 2 <= x:
            return True
        return False

# @lc code=end

